package pojo;

import java.util.Objects;

public class Person {
    private Integer id;
    private String name;


    public Person() {
    }

    public Person(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    /**
     * 获取
     *
     * @return id
     */
    public Integer getId() {
        return id;
    }

    /**
     * 设置
     *
     * @param id
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }



    /**
     * 目的：覆盖原有的比较规则
     * @param o
     * @return
     */
    @Override
    public boolean equals(Object o) {
        //即使重写了hashcode方法，两个对象的hashcode方法
        if (this == o) {
            System.out.println(this);
            System.out.println(o);
            return true;
        }
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(id, person.id) && Objects.equals(name, person.name);
    }
    /**
     * 重写了父类的hashcode()
     * @return
     */
    @Override
    public int hashCode() {
        //对 id 的值和name的值做了hash运算
        return Objects.hash(name);
    }

    @Override
    public String toString() {
        return "Person{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}
